<template>
<<<<<<< HEAD
	<view class="home">
		<view class="nav-container">
			<scroll-nav @changeCurrnet="changeCurrnet" :navList="navList"></scroll-nav>
		</view>
		<view class="content">
			<scroll-view scroll-y="true">
				<view class="news-container" v-for="item in 10" :key="item">
					<news-list @tap.native="goDetail"></news-list>
				</view>
			</scroll-view>
		</view>
	</view>

</template>

<script>
	import ScrollNav from '@/components/common/scroll-nav/scroll-nav.vue'
	import NewsList from '@/components/common/news-list/news-list.vue'
	// import { getCurrentInstance } from 'vue'
	import api from '@/api/request.js'	
	import constant from '@/api/constant.js'
	export default {
		components: {
			ScrollNav,
			NewsList
		},
		data() {
			return {
				activeNav: {},
				navList:[]
			}
		},
		onLoad() {
			this.getNavData()
		},
		onShow() {
			let list=JSON.parse(uni.getStorageSync('navList'))
			if(Array.isArray(list)){
				this.navList=list
			}else{
				this.getNavData()
			}
		},
		mounted() {
			//  vue3 获取全局定义的方法
			// const {
			// 	appContext: {
			// 		config: {
			// 			globalProperties: global
			// 		}
			// 	}
			// } = getCurrentInstance(); //3.0.11
			//console.log(global);
		},
		methods: {
			changeCurrnet(current) {
				this.activeNav = current
			},
			goDetail() {
				uni.navigateTo({
					url: '/pages/news-detail/news-detail'
				})
			},
			getNavData() {
				api.get(constant.NavList).then(({statusCode,data}) => {
					if(statusCode==200){
						this.navList=data;
						uni.setStorageSync('navList',JSON.stringify(data))
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.home {
		.nav-container {
			position: fixed;
			top: var(--window-top);
			left: 0;
			right: 0;
			z-index: 10;
			overflow-x: scroll;
			overflow-y: hidden;
		}

		.content {
			padding-top: 100rpx;
			height: auto;

			.news-container {
				margin: 0 30rpx;

			}
		}
=======
	<view>
		<view class="content">
			<text>首页</text>
			<button @tap="goMe">点击跳转我的页面</button>
		</view>
		<view><button @tap="clearData">清空</button></view>
		<view v-for="item in list" class="name-list">
			<text>名字：{{item.name}}</text>
		</view>
	</view>
</template>

<script>
	import storageKey from '/common/storage_key/storage_key.js'
	const {LIST_KEY}=storageKey
	export default {
		data() {
			return {
				title: 'Hello',
				list: [{
						name: '张-1'
					},
					{
						name: '张-2'
					},
					{
						name: '张-3'
					},
				]
			}
		},
		onLoad() {

		},
		onShow() {
			let listJson = uni.getStorageSync(LIST_KEY)
			if(listJson){
				this.list = JSON.parse(listJson)
			}
		},
		methods: {
			goMe() {
				uni.navigateTo({
					url: '/pages/404/404'
				})
			},
			clearData(){
				uni.removeStorageSync(LIST_KEY)
				this.list=[]
			}
		},
		// 页面下拉刷新事件
		onPullDownRefresh() {
			const len = this.list.length,
				data = [{
						name: '张-' + (len + 1)
					},
					{
						name: '张-' + (len + 2)
					},
					{
						name: '张-' + (len + 3)
					},
				]
			this.list = [...this.list, ...data]
			uni.stopPullDownRefresh()
		},
		// 监听页面隐藏，多次加载
		onHide() {
			// 将 data 存储在本地缓存中指定的 key 中，会覆盖掉原来该 key 对应的内容，这是一个同步接口。
			uni.setStorageSync(LIST_KEY, JSON.stringify(this.list));
		}

	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}

	.name-list {
		display: flex;
		justify-content: flex-start;
>>>>>>> master
	}
</style>
